package net.sf.fc.io.event;

import java.util.EventObject;

import java.io.File;

public final class FileCopyEvent extends EventObject {

    /**
     *
     */
    private static final long serialVersionUID = 102718533084723152L;

    /**
     * Enum that defines the status of the copy event
     * @author David Armstrong
     *
     */
    public static enum CopyStatus {

        /**
         * Copy is in progress
         */
        COPY_IN_PROGRESS,

        /**
         * Copy is complete.
         */
        COPY_COMPLETE,

        /**
         * The copy attempt failed.
         */
        COPY_FAILED,

        /**
         * The copy attempt was skipped because the destination file exists.
         */
        COPY_SKIP_DST_EXISTS,

        /**
         * The copy attempt was skipped because the destination is newer than the source.
         */
        COPY_SKIP_UPDATE_ONLY,

        /**
         * Rename of a file is complete.
         */
        RENAME_COMPLETE,

        /**
         * The attempt of a rename failed.
         */
        RENAME_FAILED
    }

    /**
     * Enum that defines levels for FileCopyEvent statuses. Modeled after
     * Log4J's Level object.
     */
    public static enum Level {
        ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
    }

    private final File srcFile;
    private final File dstFile;
    private final CopyStatus status;
    private final Level level;
    private final long bytesCopied;
    private final Throwable exception;

    public FileCopyEvent(Object source, File srcFile, File dstFile, CopyStatus status, Level level, long bytesCopied) {
        super(source);
        this.srcFile = srcFile;
        this.dstFile = dstFile;
        this.status = status;
        this.level = level;
        this.bytesCopied = bytesCopied;
        exception = null;
    }

    public FileCopyEvent(Object source, File srcFile, File dstFile, CopyStatus status, Level level, long bytesCopied, Throwable exception) {
        super(source);
        this.srcFile = srcFile;
        this.dstFile = dstFile;
        this.status = status;
        this.level = level;
        this.bytesCopied = bytesCopied;
        this.exception = exception;
    }

    public File getSrcFile() {
        return srcFile;
    }

    public File getDstFile() {
        return dstFile;
    }

    public CopyStatus getCopyStatus() {
        return status;
    }

    public Level getLevel() {
        return level;
    }

    public long getBytesCopied() {
        return bytesCopied;
    }

    public Throwable getException() {
        return exception;
    }

}
